import java.util.Arrays;
import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Gao zhao xu
 * Date: 2023-12-11
 * Time: 上午 08:13
 */
public class Test {
    public static int findRoot (int[] elem, int x) {
        while (elem[x] >= 0) {
            x = elem[x];
        }
        return x;
    }
    public static void sort (boolean[] isUsed, int[] elem, int x1, int x2) {
        int s1 = elem.length - 1;
        int s2 = elem.length - 2;
        int x1Root = findRoot(elem, x1);
        int x2Root = findRoot(elem, x2);
        if (!isUsed[x1] && !isUsed[x2]) {
            elem[x1Root] = s1;
            elem[x2Root] = s2;
        }else if (isUsed[x1]) {
            if (elem[x1Root] == s1) elem[x2Root] = s2;
            else elem[x2Root] = s1;
        }else if (isUsed[x2]) {
            if (elem[x2Root] == s1) elem[x1Root] = s2;
            else elem[x1Root] = s1;
        }
        isUsed[x1] = true;
        isUsed[x2] = true;
    }
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int t = input.nextInt();
        for (int i = 0; i < t; i++) {
            int n = input.nextInt();
            int m = input.nextInt();
            int[] elem = new int[n + 3];
            boolean[] isUsed = new boolean[n + 1];
            Arrays.fill(elem, -1);
            input.nextLine();
            for (int j = 0; j < m; j++) {
                String[] arr = input.nextLine().split(" ");
                int x1 = Integer.parseInt(arr[1]);
                int x2 = Integer.parseInt(arr[2]);
                if (arr[0].equals("A")) {
                    if (!isUsed[x1] || !isUsed[x2]) System.out.println("Not sure yet.");
                    else if (findRoot(elem, x1) != findRoot(elem, x2)) System.out.println("In different gangs.");
                    else System.out.println("In the same gang.");
                }else if (arr[0].equals("D")) {
                    sort(isUsed, elem, x1, x2);
                }
            }
        }
    }
}
